package com.kmis.common.exception;

import com.kmis.web.ApiResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author moc
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(value = RuntimeException.class)
    public ApiResult handler(RuntimeException e){
        log.error("运行时异常：----------------{}", e.getMessage());
        System.out.println("运行时异常：");
        return ApiResult.error(e.getMessage());
    }

    @ExceptionHandler(value = BusinessException.class)
    @ResponseBody
    public ApiResult BusinessExceptionHandler(BusinessException e){
        log.error("业务异常：-------{}",e.getMessage());
        System.out.println("业务出现异常");
        return ApiResult.error(e.getCode(),e.getMessage());
    }
}
